popover: Fix memory management of popovers
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 9 Jan 2014 16:21:43 +0000 (17:21 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Wed, 22 Jan 2014 16:10:06 +0000 (17:10 +0100)
commit31042fe95f73e0e93a5e7fb1584be72f6be667f2
tree796fff42ca444ed5515c4e3165d0fcf562ac11c3
parent342c23da236fdca7a3261cebf903adaf182355ab
popover: Fix memory management of popovers

Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.

The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.

This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
gtk/gtkpopover.c
gtk/gtktexthandle.c
gtk/gtkwindow.c